<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let LBD=false;
			function fun(){
				let img=document.querySelector(".con>img")//只有变量不加引号
				let h1=document.querySelector(".con>h1")
				if(LBD){
					img.setAttribute("src","../src/off.png")
					h1.innerText="灯灭了"
					h1.setAttribute("style","color: black;")
					LBD=false
				}//开灯->关灯
				else{
					img.setAttribute("src","../src/on.png")
					h1.innerText="灯亮了"
					h1.setAttribute("style","color: red;")
					LBD=true
				}
			}
		</script>
	</head>
	<body>
		<div class="con" style="text-align: center;">
			<img src="../src/off.png" alt="" height="200px" onclick="fun()">
			<h1>点击开灯</h1>
		</div>
		
	</body>
</html>
